// Token管理工具函数

const TOKEN_KEY = 'token'
const USER_INFO_KEY = 'userInfo'

// 保存token
export const setToken = (token) => {
  localStorage.setItem(TOKEN_KEY, token)
}

// 获取token
export const getToken = () => {
  return localStorage.getItem(TOKEN_KEY)
}

// 移除token
export const removeToken = () => {
  localStorage.removeItem(TOKEN_KEY)
}

// 检查是否有token
export const hasToken = () => {
  return !!getToken()
}

// 保存用户信息
export const setUserInfo = (userInfo) => {
  localStorage.setItem(USER_INFO_KEY, JSON.stringify(userInfo))
}

// 获取用户信息
export const getUserInfo = () => {
  const userInfo = localStorage.getItem(USER_INFO_KEY)
  return userInfo ? JSON.parse(userInfo) : null
}

// 移除用户信息
export const removeUserInfo = () => {
  localStorage.removeItem(USER_INFO_KEY)
}

// 清除所有认证信息
export const clearAuth = () => {
  removeToken()
  removeUserInfo()
}

// 检查是否已登录
export const isLoggedIn = () => {
  return hasToken()
} 